import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jubobao/other/Tool/JuBoToolManager.dart';
import 'package:jubobao/profile/addressBook/JuBoAddressBook.dart';
import 'package:jubobao/profile/approval/JuBoApproval.dart';
import 'package:jubobao/profile/attention/JuBoAttention.dart';
import 'package:jubobao/profile/services/JuBoServices.dart';
import 'package:jubobao/provide/JuBoLoginStateManager.dart';
import 'package:orientation/orientation.dart';
import 'package:provide/provide.dart';

class JuBoProfileModel {
  String icon;
  String text;
  JuBoProfileModel(this.icon,this.text);
}

class JuBoProfile extends StatefulWidget {
  @override
  _JuBoProfileState createState() => _JuBoProfileState();
}

class _JuBoProfileState extends State<JuBoProfile> {

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Column(
          children: <Widget>[
            profileTop(context),
            profileCenter(),
            exitButton(context)
          ],
        ),
      );
  }

  Widget profileTop (ctx){
    return profileTopInfo(ctx);
  }

  Widget profileTopInfo(ctx){
      return Container(
        child: Stack(
          alignment: Alignment.center,
          children : [
            Image.asset('assets/profile/bg.png'),
            Positioned(
              top: 100,
              left: 20,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  SizedBox(width: 45,),
                  ClipRRect(borderRadius: BorderRadius.circular(25),
                      child: Image.network('http://b-ssl.duitang.com/uploads/item/201804/25/20180425000646_fsmLS.thumb.700_0.jpeg',width: 50,)),
                  SizedBox(width: 10,),
                  profileTopInfoPhone()
                ],
              ),
            ),
            Positioned(
              bottom: 30,
              left: 15,
              right: 15,
              child: Container(
                height: 80,
                child: Card(
                  child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        profileTopInfoMenu('attention','我的考勤',(){
                          Navigator.pushNamed(ctx, JuBoAttention.routeName);
                        }),
                        profileTopInfoMenu('approval','我的审批',(){
                          print('我的审批');
                          Navigator.pushNamed(ctx, JuBoApproval.routeName);
                        }),
                        profileTopInfoMenu('services','聚玻服务',(){
                          Navigator.pushNamed(ctx, JuBoServices.routeName);

                        }),
                        profileTopInfoMenu('addressBook','通讯录',(){
                          Navigator.pushNamed(ctx, JuBoAddressBook.routeName);
                        }),
                      ],
                  ),
                ),
              ),
            )
          ],
        ),
      );
  }

   Widget profileTopInfoMenu(String menuIcon,String title,Function f){
    return InkWell(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Image.asset('assets/profile/$menuIcon.png',width: 25,),
          SizedBox(height: 5,),
          Text(title)
        ],
      ),
      onTap: f,
    );
  }

  Widget profileTopInfoPhone(){
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
      Text('吴炎凉',style: TextStyle(color: Colors.white,fontSize: 18),),
      Text('13291872307  已认证',style: TextStyle(color: Colors.white,fontSize: 18)),
    ],
    );
  }

    Widget profileCenter (){

    List profileModels = [JuBoProfileModel('message','会话列表'),
                          JuBoProfileModel('myStudy','我的学习'),
                          JuBoProfileModel('myMoney','我的钱包'),
                          JuBoProfileModel('myForum','我的论坛'),
                          JuBoProfileModel('address','地址管理'),
                          JuBoProfileModel('profileSetting','个人设置'),
                          JuBoProfileModel('about','关于聚玻宝'),
    ];

    return ListView.separated(
        padding: EdgeInsets.zero,
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        itemBuilder: (ctx,index){
          JuBoProfileModel model = profileModels[index];
          return profileCenterItem(model);
        },
        separatorBuilder: (ctx,index){
          return Divider();
        },
        itemCount: profileModels.length,
    );
  }

  Widget profileCenterItem (JuBoProfileModel model){
    return profileCenterItemImage(model);
  }

  Widget profileCenterItemImage (JuBoProfileModel model){
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 8),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            children: <Widget>[
              SizedBox(width: 15,),
              Image.asset('assets/profile/${model.icon}.png',width: 20,),
              SizedBox(width: 8,),
              Text(model.text,style: TextStyle(fontSize: 16),),
            ],
          ),
          Icon(Icons.arrow_forward_ios,color: Colors.black54,size: 16,)
        ],
      ),
    );
  }

  Widget exitButton(ctx){
      return Padding(
        padding: const EdgeInsets.all(12),
        child: Container(
          width: 320,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(10)),
          ),
          child: Container(
            width: 100,
            height: 50,
            child: FlatButton(
                onPressed: (){
                  Provide.value<JuBoLoginState>(ctx).changeState(false);
                  JuBoToolManager.setLoginState(false);
                },
                child: Text('退出登录',style: TextStyle(color: Colors.black54),),
            ),
          ),
        ),
      );
   }
}

